package com.expert.service;

import com.expert.constant.RabbitMQConstant;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @ClassName: RabbitSendService
 * @Author: cxs
 * @Date: 2024/03/26 19:06
 * @Description:
 *
 **/
@Service
public class RabbitSendService {
    @Autowired
    RabbitTemplate rabbitTemplate;



    /**
     * 发送消息
     * @return
     */
    public String send(Long expertId,Long projectId){
        //邮件发送消息
        rabbitTemplate.convertAndSend(RabbitMQConstant.EXCHANGE_TOPIC,RabbitMQConstant.KEY_EMAIL,"{'expertId':"+expertId+",'projectId':"+projectId+"}");
        //系统发送消息
        rabbitTemplate.convertAndSend(RabbitMQConstant.EXCHANGE_TOPIC,RabbitMQConstant.KEY_SYS,"{'expertId':"+expertId+",'projectId':"+projectId+"}");
        return "发送成功";
    }

    public String cancelProjectNotice(Long expertId,Long projectId){
        rabbitTemplate.convertAndSend(RabbitMQConstant.EXCHANGE_TOPIC,RabbitMQConstant.KEY_CANCEL_PROJECT_EMAIL,"{'expertId':"+expertId+",'projectId':"+projectId+"}");
        rabbitTemplate.convertAndSend(RabbitMQConstant.EXCHANGE_TOPIC,RabbitMQConstant.KEY_CANCEL_PROJECT_SYS,"{'expertId':"+expertId+",'projectId':"+projectId+"}");
        return "发送成功";
    }

    public void sendReExtractMessage(Long expertId, Long id) {
        rabbitTemplate.convertAndSend(RabbitMQConstant.EXCHANGE_TOPIC,RabbitMQConstant.KEY_RE_EXTRACT,"{'expertId':"+expertId+",'projectId':"+id+"}");
    }

    /**
     * 取消抽取结果
     * @param expertId 专家id
     * @param id 项目id
     */
    public void sendCancelExtractResult(Long expertId, Long id) {
        rabbitTemplate.convertAndSend(RabbitMQConstant.EXCHANGE_TOPIC,RabbitMQConstant.KEY_CANCEL_EXTRACT_RESULT,"{'expertId':"+expertId+",'projectId':"+id+"}");
    }
}
